//
// Created by hjie on 23-5-15.
//
#pragma once

#include <string>
#include <vector>
#include <cstdlib>
#include <arpa/inet.h>
#include <unistd.h>

#define BUFFER_SIZE 4096

class DataBuffer
{
public:
    DataBuffer(int fd);
    ~DataBuffer();
    uint8_t * Data();
    int Length();
    int FreeSize();
    void RemoveData(int length);
    int ReadData(int & status);
    int WriteData(const uint8_t * data, int length);
    uint8_t * ReadNByte(int size);
    void PushDataBuffer(uint8_t * data, int length);
public:
    // for udp server/client api
    int ReadData(struct sockaddr * remote_addr, socklen_t * remote_len, int & status);
    int WriteData(const uint8_t * data, int length, struct sockaddr * remote, socklen_t len);
private:
    int m_fd;

    int m_buffer_begin_index;
    int m_data_current_index;
    int m_data_end_index;
    int m_buffer_end_index;
private:
    std::vector<uint8_t> m_data;
};


